package ca.jerg.wizard;

import javax.swing.*;
import javax.swing.text.*;
import java.util.ArrayList;

import com.nexes.wizard.WizardPanelDescriptor;

public class ErgWizardWarmUpDescriptor extends WizardPanelDescriptor
{
    public static final String IDENTIFIER = "WARMUP_PANEL";
    
    private ErgWizard ergWizard;
    
    public ErgWizardWarmUpDescriptor( ErgWizard erg ) 
    {
        super(IDENTIFIER,new ErgWizardWarmUpPanel());
                
        // reference to the top level wizard
        ergWizard = erg;
    }
    
    public Object getNextPanelDescriptor() 
    {
        return FINISH;
    }
    
    public Object getBackPanelDescriptor() 
    {
        return ErgWizardSetDescriptor.IDENTIFIER;
    }
      
	public void aboutToDisplayPanel()
	{
		ArrayList sets = ergWizard.getSets();
		JTextPane textPane = ((ErgWizardWarmUpPanel)super.getPanelComponent()).getTextPane();
		
		StyledDocument outline = textPane.getStyledDocument();
				
		try
		{
			// remove any existing text
			outline.remove(0,outline.getLength());
			
			// generate the workout description
			for ( int i=0; i<sets.size(); i++ )
			{
				ErgWizardSetData set = (ErgWizardSetData)sets.get(i);
				set.setThresholdWatts(ergWizard.getThresholdWatts());
				set.calculateSet();
				
				String s = "-+ " + set.getType() + " +-\n" + 
					set.getRepeats() + "x[" +
					set.getWorkTime() + " minutes " +
					"@ " + set.getWorkLoad() + " watts " +
					"with " + set.getRestTime() + " minutes " +
					"@ " + set.getRestLoad() + " watts]\n\n";					

				outline.insertString(outline.getLength(),s,null);			
			}
			
		}
		catch ( BadLocationException e )
		{
			e.printStackTrace();
		}
		
		textPane.setCaretPosition(0);
	}    
}
